import filesize from 'rollup-plugin-filesize'
import { uglify } from 'rollup-plugin-uglify'
import { minify } from 'uglify-es'

import baseConfig from './rollup.config.base'
import { name, version, author } from '../package.json'

const banner =
    `${'/*!\n' + ' * '}${name}.js v${version}\n` +
    ` * (c) 2021-${new Date().getFullYear()} ${author}\n` +
    ` * Released under the MIT License.\n` +
    ` */`

export default [
    // .js, .cjs.js, .esm.js
    {
        ...baseConfig,
        output: [
            // umd development version with sourcemap
            {
                file: `dist/${name}.js`,
                format: 'umd',
                name: 'res',
                banner,
                sourcemap: true
            }
        ],
        plugins: [...baseConfig.plugins, filesize()]
    },
    // .min.js
    {
        ...baseConfig,
        output: [
            // umd with compress version
            {
                file: `dist/${name}.min.js`,
                format: 'umd',
                name: 'res',
                banner
            }
        ],
        plugins: [
            ...baseConfig.plugins,
            uglify(
                {
                    compress: {
                        drop_console: true
                    }
                },
                minify
            ),
            filesize()
        ]
    }
]